<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <g:set var="entityName" value="${message(code: 'estate.label', default: 'Estate')}" />
    <title>押品价值波动</title>
    <style>
    .contact-stat{
        padding: 8px 0px;
        text-align: center;
    }
    .contact-stat span{
        font-size: 13px;
        color: #88898c;
        margin-bottom: 10px;
    }
    .contact-stat strong{
        font-size: 13px;
        word-wrap: break-word;
    }
    .nav-tabs{
        border-bottom: none;
    }
    .hpanel > .panel-footer, .hpanel > .panel-section{
        background: #f9f9f9;
    }

    .newFontSize{
        font-size: 12px;
    }
    table>tbody>tr>td, table>tbody>tr>th,.table>tfoot>tr>td, table>tfoot>tr>th, table>thead>tr>td, table>thead>tr>th{
        padding: 8px;
        line-height: 1.42857143;
    }
    </style>
</head>
<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li class="active">
                        <span>押品价值波动</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                押品价值波动
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="priceFluctuationsRatioWarning" class="form-horizontal" role="form" id="form">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" id="searchBtn"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>
                <div class="panel-body seach-group" id="bug1">
                    <div class="row">
                        <div class="form-group col-sm-3">
                            <label for="district" class="col-sm-3 control-label">房屋用途</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="residentialType" id="residentialType" from="${com.cindata.dictionary.BuildingTypeDict.listOrderById()}" valueMessagePrefix="status" optionKey="id" optionValue="name"
                                      value="${params?.residentialType}" noSelection="${['': '请选择房屋用途']}"/>
                            </div>
                        </div>

                        <div class="form-group col-sm-3">
                            <label for="district" class="col-sm-3 control-label">城市</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="city" id="city" from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}" valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                    value="${params?.city}" noSelection="${['-1': '请选择城市']}"/>
                            </div>
                        </div>

                        <div class="form-group col-sm-3">
                            <label for="district" class="col-sm-3 control-label">行政区</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="district" id="district" from="${districtList}" valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                    value="${params?.district}" noSelection="${['-1': '请选择行政区']}"/>
                            </div>

                        </div>
                    </div>
                </div>
        </g:form>
    </div>
</div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <!-- <a class="btn btn-primary btn-xs" type="submit" href="/riskWarning/releasePriceFluctuationsWarning"><i class="fa fa-paper-plane"></i> 发布预警</a> -->
                    <!-- <g:link class="btn btn-info btn-xs"  action="excuteComponentWithParam" params="[componentCode: 'priceFluctuationsRatioWarning']">发布预警</g:link> -->
                    <button class="btn btn-warning2 btn-xs" type="submit" onclick="searchMap()"><i class="fa fa-map-marker"></i> 查看地图</button>
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                全部押品价值波动
            </div>
            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover text-center" id="estateTable">
                        <thead>
                        <tr>
                            <g:sortableColumn property="externalId" title="押品编号"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="buildingType" title="房屋用途"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="city" title="城市"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="district" title="行政区"   class="text-center" params="${params}"/>
                            <g:sortableColumn property="sourceAddress" title="房屋坐落"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="buildArea" title="面积(平米)" class="text-center" params="${params}"/>
                            <g:sortableColumn property="loansAmount" title="贷款金额(元)"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="loansBalance" title="贷款余额(元)"   class="text-center" params="${params}"/>
                            <g:sortableColumn property="totalPrice" title="当前估值(元)" class="text-center" params="${params}"/>
                            <!-- <g:sortableColumn property="cltv" title="押品风险"  class="text-center" params="${params}"/> -->
                            <g:sortableColumn property="priceFluctuationsRatio" title="价值波动率"   class="text-center" params="${params}"/>
                            <g:sortableColumn property="warningStatus" title="处置状态"   class="text-center" params="${params}"/>
                            <th colspan="2" class="col-md-1 text-center sortable" style="color: #34495e;">操作项</th>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${riskWarningList}">
                            <tr>
                                <td class="text-center"><g:link style="color: #3498DB" action="priceFluctuationsRatioWarningShow" id="${it?.collateral.id}" params="[status: it?.status?.name]" class="firstTd">${it?.collateral?.externalId}</g:link></td>
                                <td class="text-center">${it?.collateral?.estate?.buildingType?.name}</td>
                                <td class="text-center">${it?.collateral?.city?.name}</td>
                                <td class="text-center">${it?.collateral?.district?.name}</td>
                                <td class="text-center">${it?.collateral?.estate?.sourceAddress}</td>
                                <td class="text-center">${it?.collateral?.estate?.buildArea}</td>
                                <td class="text-center">${it?.collateral?.estate?.loansAmount}</td>
                                <td class="text-center">${it?.collateral?.estate?.loansBalance}</td>
                                <td class="text-center">${it?.collateral?.latestEvaluatePrice}</td>
                                <!-- <td class="text-center"><g:if test="${it?.collateral?.cltv>=0&&it?.collateral?.cltv<=0.6}">低</g:if>
                                <g:if test="${it?.collateral?.cltv>0.6&&it?.collateral?.cltv<=0.8}">中</g:if>
                                <g:if test="${it?.collateral?.cltv>0.8&&it?.collateral?.cltv<=1}">高</g:if>
                                <g:if test="${it?.collateral?.cltv>1}">损失</g:if>
                                </td> -->

                                <g:if test="${it?.collateral?.estate?.priceFluctuationsRatio && it?.collateral?.estate?.priceFluctuationsRatio >= 0}">
                                    <td class="text-center">上升 <g:formatNumber number="${it?.collateral?.estate?.priceFluctuationsRatio*100}"  type="number" minFractionDigits="2" maxFractionDigits="2" />%</td>
                                </g:if>
                                <g:elseif test="it?.collateral?.estate?.priceFluctuationsRatio && it?.collateral?.estate?.priceFluctuationsRatio < 0">
                                    <td class="text-center">下降 <g:formatNumber number="${-it?.collateral?.estate?.priceFluctuationsRatio*100}"  type="number" minFractionDigits="2" maxFractionDigits="2" />%</td>
                                </g:elseif>
                                <g:else>
                                    <td class="text-center">-</td>
                                </g:else>
                                <td class="text-center">${it?.status?.name}</td>
                                <g:if test="${it?.status?.name == '已处置'}">
                                    <td class="text-center">
                                        <div style="margin-bottom: 2px;">
                                            <div class="btn btn-xs btn-outline btn-success" style="color: #fff" disabled>
                                                已处置
                                            </div>
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <div class="btn btn-xs btn-outline btn-danger" style="width: 52px; margin-top: 2px;color: #fff" disabled>
                                            删除
                                        </div>
                                    </td>
                                </g:if>
                                <g:else>
                                    <td class="text-center">
                                        <div style="margin-bottom: 2px;">
                                            <a href="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                                已处置
                                            </a>
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <a href="${it?.id}" class="btn btn-xs btn-outline btn-danger deleteButton" style="width: 52px; margin-top: 2px;">
                                            删除
                                        </a>
                                    </td>
                                </g:else>
                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="priceFluctuationsRatioWarning" total="${riskWarningcount ?: 0}" params="${params}"/>
                </div>
            </div>
        </div>
    </div>

</div>

<script>
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
                title: "该笔押品已经完成预警处置吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/riskWarningDeal',
                    data:{
                        id:id
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success"){
                            window.location.reload();
                        }else{
                            swal("已处置失败，请稍后重试", "", "error");
                        }
                    }
                })

            });
    });
    $(".deleteButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
                title: "确定删除该笔押品的预警处置吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/riskWarningDelete',
                    data:{
                        id:id
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success") {
                            window.location.reload();
                        } else{
                            swal("删除失败，请稍后重试", "", "error");
                        }
                    }
                })
            })
    });
    //城市切换
    $("#city").bind("change", function(){
        $("#district option").remove();
        $("#s2id_district span:first").html("请选择行政区");
        var city = $("#city").val();
        $("#district").append("<option value='-1' >请选择行政区</option>");
        if(city=='-1'){
            return
        }
        $.ajax({
            url: "/estate/districtList",
            type: "POST",
            data: {'city': city} ,
            success: function(result){
                for(var i=0; i < result.districtList.length; i++){
                    $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    });
    // $("#city").change();
    //条件重置
    $("#resetBtn").click(function () {
        $("#s2id_residentialType span:first").html("请选择房屋用途");
        $("#residentialType").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_district span:first").html("请选择行政区");
        $("#district").val("");
    });
    //查看地图
    function searchMap() {
        var risk=$("#risk").val(),
            city=$('#city').val(),
            district=$('#district').val(),
            precinct=$('#precinct').val(),
            inputData={
                risk:risk,
                city:city,
                district:district,
                precinct:precinct
            };
        if(city=="-1"){
            toastr.error('请选择城市！');
            return
        }
        //window.location.href="/map/cluster?currentMap=clusterMap&flag=true&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
</script>

</body>
</html>
